﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyOA.Model;
using MyOA.BLL;

namespace MyOA.UI.File
{
    public partial class FileSearch : System.Web.UI.Page
    {
        protected IList<FileInfo> Files
        {
            get { return (IList<FileInfo>)ViewState["files"]; }
            set{ViewState["files"]=value;}
        }
        FileSearchManage fsm = new FileSearchManage();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["loginId"] == null)
            {
                Response.Redirect("~/Login.aspx");
                return;
            }

        }
        //显示搜索的文件结果
        protected void DisplayFilesInfo(string fileName, string createUser, string containWods, string beginTime, string endTime)
        {
            IList<FileInfo> files = fsm.GetFilesInfoByConditions(fileName, createUser, containWods, beginTime, endTime);
            Files = files;
            PagedDataSource pdsFileInfo = new PagedDataSource();
            pdsFileInfo.DataSource = files;
            pdsFileInfo.AllowPaging = true;
            pdsFileInfo.CurrentPageIndex = anpFileInfo.CurrentPageIndex - 1;
            pdsFileInfo.PageSize = anpFileInfo.PageSize;
            anpFileInfo.RecordCount = files.Count;
            gvFilesInfo.DataSource = pdsFileInfo;
            gvFilesInfo.DataBind();
        }
        protected void imgbtnSearch_Click(object sender, ImageClickEventArgs e)
        {
            gvFilesInfo.Visible = true;


            string fileName = txtFileName.Text.Trim();
            string createUser = txtCreateUser.Text.Trim();
            string containWods = txtContainWords.Text.Trim();

            string beginTime = "";
            string endTime = "";
            if (lnkbtnOption.Text == "搜索选项 >>")
            {
                if (txtBeginTime.Text == "" || txtEndTime.Text == "")
                {
                    Response.Write("<script>alert('时间不能为空！');</script>");
                }
                else
                {
                    beginTime = txtBeginTime.Text + " 00:00:00";
                    endTime = txtEndTime.Text + " 23:59:59";
                    DisplayFilesInfo(fileName, createUser, containWods, beginTime, endTime);
                }
            }
            else
            {
                
                DisplayFilesInfo(fileName, createUser, containWods, beginTime, endTime);
            }

        }

        protected void lnkbtnOption_Click(object sender, EventArgs e)
        {
            if (lnkbtnOption.Text == "搜索选项 >>")
            {
                pnlOption.Visible = false;
                lnkbtnOption.Text = "搜索选项 <<";
            }
            else
            {
                pnlOption.Visible = true;
                lnkbtnOption.Text = "搜索选项 >>";
            }
        }

        protected void anpFileInfo_PageChanged(object sender, EventArgs e)
        {
            PagedDataSource pdsFileInfo = new PagedDataSource();
            pdsFileInfo.DataSource = Files;
            pdsFileInfo.AllowPaging = true;
            pdsFileInfo.CurrentPageIndex = anpFileInfo.CurrentPageIndex - 1;
            pdsFileInfo.PageSize = anpFileInfo.PageSize;
            anpFileInfo.RecordCount = Files.Count;
            gvFilesInfo.DataSource = pdsFileInfo;
            gvFilesInfo.DataBind();
        }

    }
}
